/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kallsonys.session;

import com.kallsonys.dao.ProductDAO;

import com.kallsonys.service.Campaign;
import com.kallsonys.service.ElementList;
import com.kallsonys.service.ElementListPage;
import com.kallsonys.service.Item;
import com.kallsonys.service.Product;
import com.kallsonys.service.Range;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.sql.DataSource;

/**
 *
 * @author allan
 */
@WebService(serviceName = "ProductsService")
@Stateless
public class Products {

    private ProductDAO dao;
    @Resource(mappedName = "jdbc/OMS", type = DataSource.class)
    DataSource dsOMS;

    @PostConstruct
    void postConstruct() {
        dao = new ProductDAO(dsOMS);
    }

    public List<Item> getAllCategorys(boolean part1) throws Exception {
        List<Item> item = null;
        try {

            item = dao.getAllCategorys();
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public List<Campaign> getAllCampaign(boolean part1) throws Exception {
         List<Campaign> item = null;
        try {

            item = dao.getAllCampaign();
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public ElementListPage<Product> getProductsByIdCategory(@WebParam(name = "category") com.kallsonys.service.StringPage category) throws Exception {
        ElementListPage<Product> item = null;
        try {

            item = dao.getByIdCategory(category);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public ElementListPage<Product> getProductsByDescription(@WebParam(name = "description") com.kallsonys.service.StringPage description) throws Exception {
        ElementListPage<Product> item = null;
        try {

            item = dao.getProductsByDescription(description);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public com.kallsonys.service.Product getProductsById(@WebParam(name = "IdProduct") long IdProduct) throws Exception {
        com.kallsonys.service.Product item = null;
        try {

            item = dao.getProductsById(IdProduct);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public ElementListPage<Product> getProductsByName(@WebParam(name = "name") com.kallsonys.service.StringPage name) throws Exception {
        ElementListPage<Product> item = null;
        try {

            item = dao.getProductsByName(name);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }

    public ElementList<Product> getProductsByRanking(@WebParam(name = "range") Range range) throws Exception {
        ElementList<Product> item = null;
        try {

            item = dao.getProductsByRanking(range);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }
    
    
    public List<Product> getProductsRelated(@WebParam(name = "idProduct") long idProduct) throws Exception {
        List<Product> item = null;
        try {

            item = dao.getProductsRelated(idProduct);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }
    
    public List<Product> getProductsNewest(@WebParam(name = "dummy") boolean dummy) throws Exception {
        List<Product> item = null;
        try {

            item = dao.getProductsNewest();
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }

        return item;
    }
}
